﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Library.StringExt
{
    public class DateTimeExt
    {

        #region 时间戳

        #region 13位时间戳
        public static long ConvertDateTimeToInt(DateTime? time = null)
        {
            if (time == null)
            {
                time = new DateTime();
            }
            DateTime tempTime = time.Value;
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
            long t = (tempTime.Ticks - startTime.Ticks) / 10000;   //除10000调整为13位      
            return t;
        }
        #endregion

        #region 10位时间戳
        public static long ConvertDateTimeToIntBy10(DateTime? time = null)
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds);
        }
        #endregion


        #endregion

    }
}
